package com.crm.service.impl.knowledgeitem;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customMapper.knowledgeitem.KnowledgeItemCustomMapper;
import com.crm.dao.mapper.knowledgeitem.KnowledgeItemMapper;
import com.crm.model.entity.knowledgeitem.KnowledgeItem;
import com.crm.model.entity.knowledgeitem.KnowledgeItemExample;
import com.crm.service.knowledgeitem.KnowledgeItemDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 知识条目
 * @Author lixq-f
 * @Date 2021/5/7
 * @Version V1.0
 **/
@Service
public class KnowledgeItemDbServiceImpl implements KnowledgeItemDbService {

    @Autowired
    private KnowledgeItemMapper itemMapper;
    @Autowired
    private KnowledgeItemCustomMapper itemCustomMapper;

    @Override
    public Boolean insert(KnowledgeItem item) {
        return itemMapper.insert(item) > 0;
    }

    @Override
    public List<KnowledgeItem> selectList() {
        KnowledgeItemExample example = new KnowledgeItemExample();
        KnowledgeItemExample.Criteria criteria = example.createCriteria();
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        example.setOrderByClause("create_tm asc");
        return itemMapper.selectByExample(example);
    }

    @Override
    public Boolean update(KnowledgeItem item) {
        return itemMapper.updateByPrimaryKeySelective(item) > 0;
    }


    @Override
    public Boolean deleteById(String itemId, short deleteStatus) {
        return itemCustomMapper.deleteById(itemId, deleteStatus);
    }


    @Override
    public KnowledgeItem selectKnItemByKey(String itemId) {
        return itemMapper.selectByPrimaryKey(itemId);
    }


    @Override
    public Integer selectItemCount() {
        KnowledgeItemExample example = new KnowledgeItemExample();
        KnowledgeItemExample.Criteria criteria = example.createCriteria();
        criteria.andDeleteStatusEqualTo((short)0);
        return (int) itemMapper.countByExample(example);
    }
}
